package com.util.net;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;

public class Test {
    public void setLocalProxy() {
        Properties prop = System.getProperties();
        prop.setProperty("http.proxyHost", "219.149.233.179");
        prop.setProperty("http.proxyPort", "8080");
    }
    public void removeLocalProxy() {
        Properties prop = System.getProperties();
        prop.remove("http.proxyHost");
        prop.remove("http.proxyPort");
    }

    public void showHttpProxy(Object... proxy) {
        URL url = null;
        try {
            url = new URL("http://www.mov6.com/title/tt0388482/");
        } catch (MalformedURLException e) {
            return;
        }
        try {
            URLConnection conn = null;
            switch (proxy.length) {
                case 0:
                    conn = url.openConnection();
                    break;
                case 1:
                    conn = url.openConnection((Proxy) proxy[0]);
                    break;
                default:
                    break;
            }

            if (conn == null)
                return;
            conn.setConnectTimeout(3000);
            InputStream in = conn.getInputStream();
            byte[] b = new byte[1024];
            try {
                while (in.read(b) > 0) {
                    System.out.println(new String(b));
                }
            } catch (IOException e1) {
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }

    }
    
    public static void main(String[] args) {
        Test proxy = new Test();

        proxy.setLocalProxy();
        proxy.showHttpProxy();
    }
}
